﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Platform_Controller : MonoBehaviour
{
    public Transform LeftBoundary, RightBoundary;
    public float moveSpeed;
    private float left, right,faceDirection;
    // Start is called before the first frame update
    void Start()
    {
        faceDirection = 1;
        left = LeftBoundary.position.x;
        right = RightBoundary.position.x;
        Destroy(LeftBoundary.gameObject);
        Destroy(RightBoundary.gameObject);    
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        if (transform.position.x <= left)
            faceDirection = 1;
        if (transform.position.x >= right)
            faceDirection = -1;
        
        transform.position = new Vector3(transform.position.x + faceDirection * Time.fixedDeltaTime * moveSpeed,
                                              transform.position.y, 0);
    }
}
